package com.shop.cloud.controller.finance;

import io.swagger.annotations.ApiOperation;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import cn.jpush.api.common.resp.APIConnectionException;
import cn.jpush.api.common.resp.APIRequestException;

import com.shop.cloud.JPush.MsgPushUtils;
import com.shop.cloud.common.mybatis.BaseController;
import com.shop.cloud.dao.hongfu.UserDao;
import com.shop.cloud.dao.hongfu.WithdrawHistoryDao;
import com.shop.cloud.domain.hongfu.BalanceHistory;
import com.shop.cloud.domain.hongfu.BankAccount;
import com.shop.cloud.domain.hongfu.InfundDenomination;
import com.shop.cloud.domain.hongfu.IntegralSetting;
import com.shop.cloud.domain.hongfu.Message;
import com.shop.cloud.domain.hongfu.PointsHistory;
import com.shop.cloud.domain.hongfu.Shop;
import com.shop.cloud.domain.hongfu.SysConfig;
import com.shop.cloud.domain.hongfu.User;
import com.shop.cloud.domain.hongfu.WithdrawConfig;
import com.shop.cloud.domain.hongfu.WithdrawHistory;
import com.shop.cloud.domain.system.SysRole;
import com.shop.cloud.filter.CurrentUserId;
import com.shop.cloud.filter.IgnoreAuth;
import com.shop.cloud.model.request.DenominationSetupRequest;
import com.shop.cloud.model.request.GetDenominationListRequest;
import com.shop.cloud.model.request.GetFundListRequest;
import com.shop.cloud.model.request.GetInfundListRequest;
import com.shop.cloud.model.request.GetPointsListRequest;
import com.shop.cloud.model.request.GiveFundRequest;
import com.shop.cloud.model.request.GivePointsRequest;
import com.shop.cloud.model.request.ReduceFundRequest;
import com.shop.cloud.model.request.ReducePointsRequest;
import com.shop.cloud.model.response.DenominationSetupResponse;
import com.shop.cloud.model.response.GetDenominationListResponse;
import com.shop.cloud.model.response.GetFundListResponse;
import com.shop.cloud.model.response.GetInfundListResponse;
import com.shop.cloud.model.response.GetPointsListResponse;
import com.shop.cloud.model.response.GiveFundResponse;
import com.shop.cloud.model.response.GivePointsResponse;
import com.shop.cloud.model.response.ReduceFundResponse;
import com.shop.cloud.model.response.ReducePointsResponse;
import com.shop.cloud.service.hongfu.WithdrawConfigService;
import com.shop.cloud.service.hongfu.impl.BalanceHistoryService;
import com.shop.cloud.service.hongfu.impl.BankAccountService;
import com.shop.cloud.service.hongfu.impl.CityService;
import com.shop.cloud.service.hongfu.impl.GoodsOrderService;
import com.shop.cloud.service.hongfu.impl.InfundDenominationService;
import com.shop.cloud.service.hongfu.impl.IntegralSettingService;
import com.shop.cloud.service.hongfu.impl.MessageService;
import com.shop.cloud.service.hongfu.impl.PointsHistoryService;
import com.shop.cloud.service.hongfu.impl.ProvinceService;
import com.shop.cloud.service.hongfu.impl.RegionService;
import com.shop.cloud.service.hongfu.impl.ShopAptitudeService;
import com.shop.cloud.service.hongfu.impl.ShopImageService;
import com.shop.cloud.service.hongfu.impl.ShopService;
import com.shop.cloud.service.hongfu.impl.ShopTypeService;
import com.shop.cloud.service.hongfu.impl.SysConfigService;
import com.shop.cloud.service.hongfu.impl.UserService;
import com.shop.cloud.service.hongfu.impl.WithdrawHistoryService;
import com.shop.cloud.service.system.impl.SysRoleService;
import com.shop.cloud.util.Page;
import com.shop.cloud.util.Response;
import com.shop.cloud.util.ResponseUtil;

@RestController
@RequestMapping(value = "finance")
public class FinanceController extends BaseController {

	private static final Logger logger = Logger.getLogger(FinanceController.class);

	@Autowired
	private ShopService shopService;
	
	@Autowired
	private ShopTypeService shopTypeService;
	
	@Autowired
	private ShopImageService shopImageService;
	
	@Autowired
	private RegionService regionService;
	
	@Autowired
	private ShopAptitudeService shopAptitudeService;
	
	@Autowired
	private SysConfigService sysConfigService;
	
	@Autowired
	private BankAccountService bankAccountService;
	
	
	@Autowired
	private WithdrawHistoryDao withdrawHistoryDao;
	
	@Autowired
	private CityService cityService;
	
	@Autowired
	private ProvinceService provinceService;
	
	@Autowired
	private GoodsOrderService goodsOrderService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private BalanceHistoryService balanceHistoryService;
	
	@Autowired
	private PointsHistoryService pointsHistoryService;
	
	@Autowired
	private InfundDenominationService infundDenominationService;
	
	@Autowired
	private IntegralSettingService integralSettingService;
	
	@Autowired
	private UserDao userDao;
	
	@Autowired
	private WithdrawHistoryService withdrawHistoryService;
	
	@Autowired
	private WithdrawConfigService withdrawConfigService;
	
	@Autowired
	private MessageService messageService;
	
	@Autowired
	private SysRoleService sysRoleService;
	
	//@MagicPermission
	@ApiOperation(value = "获取流水明细列表", notes = "获取流水明细列表")
	@RequestMapping(value = "fundList", method = RequestMethod.POST)
	@ResponseBody
	public Response fundList(HttpServletRequest request, HttpServletResponse response,@CurrentUserId Long userId,@RequestBody GetFundListRequest getFundListRequest) {
		logger.debug("获取流水明细列表");
		List<GetFundListResponse> datas = new ArrayList<GetFundListResponse>();
		GetFundListResponse data = null;
		Map<String, Object> params = null;
		
		List<BalanceHistory> balances = null;
		User user = null;
		
		params = new HashMap<String, Object>();
		
//		switch(getFundListRequest.getSearchType()) {
//		case GetFundListRequest.SEARCH_TYPE_TRADER_USER_ID :
//			params.put("userId", getFundListRequest.getKeyword());
//			break;
//		case GetFundListRequest.SEARCH_TYPE_TRADER_NICKNAME :
//			break;
//		case GetFundListRequest.SEARCH_TYPE_TRADER_NO :
//			params.put("orderNo", getFundListRequest.getKeyword());
//			break;
//		case GetFundListRequest.SEARCH_TYPE_TRADE_OBJER_USER_ID :
//			
//			break;
//		case GetFundListRequest.SEARCH_TYPE_TRADE_OBJER_NICKNAME :
//			
//			break;
//		}
		//tradeType;
		//searchType;
		//key;
	    //start_time;
	    //end_time;
		
		//条件查询
		if(!(getFundListRequest.getStart_time() == null || getFundListRequest.getStart_time().equals(""))){
			params.put("startTime", getFundListRequest.getStart_time());
		}
		if(!(getFundListRequest.getEnd_time() == null || getFundListRequest.getEnd_time().equals(""))){
			params.put("endTime", getFundListRequest.getEnd_time());
		}
//		if (!(String.valueOf(getFundListRequest.getTradeType())==null|| String.valueOf(getFundListRequest.getTradeType())==null)) {
//			params.put("type", getFundListRequest.getTradeType());
//		}
		if (getFundListRequest.getTradeType()!=0) {
			params.put("type", getFundListRequest.getTradeType());
		}
		if(!(getFundListRequest.getUserId() == null || getFundListRequest.getUserId().equals(""))){
			params.put("userId", getFundListRequest.getUserId());
		}
		
		if(!(getFundListRequest.getOrderNo() == null || getFundListRequest.getOrderNo().equals(""))){
			params.put("orderNo", getFundListRequest.getOrderNo());
		}
		if(!(getFundListRequest.getObjId() == null || getFundListRequest.getObjId().equals(""))){
			params.put("objId", getFundListRequest.getObjId());
		}
		if(!(getFundListRequest.getObjNickName() == null || getFundListRequest.getObjNickName().equals(""))){
			params.put("objNickName", getFundListRequest.getObjNickName());
		}
		params.put("orderBy", "create_time desc");
		
		//分页
		long count = balanceHistoryService.count(params);
		int pageIndex = getFundListRequest.getPageIndex_();
		int pageSize = getFundListRequest.getPageSize_();
		Page<GetFundListResponse> page = new Page<GetFundListResponse>(pageIndex,pageSize);
		int limitStart = (pageIndex - 1) * pageSize;
		params.put("limitStart", limitStart);
		
		int limitEnd = pageSize;
		params.put("limitEnd", limitEnd);
		balances = balanceHistoryService.find(params);
		
		for(BalanceHistory balance : balances) {
			
			data = new GetFundListResponse();
			
			data.setId(balance.getId());
			data.setTradeNo(balance.getOrderNo());// 需要修改
			data.setTradeUserId(balance.getUserId());
			data.setTradeType(balance.getType());
			data.setTradeObjUserId(0l);
			data.setTradeTime(getStringDateTime(balance.getCreateTime()));
			if (balance.getType() ==1 || balance.getType() ==2 || balance.getType() ==4 || balance.getType() ==8 || balance.getType() ==9 || balance.getType() ==11 || balance.getType() ==12 || balance.getType() ==15 || balance.getType() ==16 || balance.getType() ==17 || balance.getType() ==19 || balance.getType() ==20) {
				if (balance.getType() ==2 || balance.getType() ==4  || balance.getType() ==9 || balance.getType() ==12 || balance.getType() ==20) {
					data.setAmount(0-balance.getAmount());
				}else {
					data.setAmount(balance.getAmount());
				}
			}else{
				if (balance.getType()==3 || balance.getType() ==23) {
					data.setCredits(0-balance.getCredits());
				}else {
					data.setCredits(balance.getCredits());
				}
			}
			
			params = new HashMap<String, Object>();
			if(!(getFundListRequest.getNickName() == null || getFundListRequest.getNickName().equals(""))){
				params.put("nickname", getFundListRequest.getNickName());
			}
			params.put("id", balance.getUserId());
			//用户权限
			//获得权限和roleID
			User user2 = userDao.getRoleId(userId);
			if (user2.getAuthority()==1) {
			}
			
			if (user2.getAuthority()==2) {
				params.put("roleId",user2.getRoleId());
			}
			user = userService.findOne(params);
			if(user != null) {
				data.setTradeNickname(user.getNickname());
				data.setTradeObjNickname("admin");
				datas.add(data);
			} else {
				data.setTradeNickname("");
				data.setTradeObjNickname("");
			}
//			data.setTradePrice((balance.getChangeAmount() > 0 ? "+" : "") + balance.getChangeAmount() + "元");
			
		}
		
		page.setData(datas);
		page.setTotalCount((int)count);

		
		return ResponseUtil.ok(page);
	}
	
	@ApiOperation(value = "获取流水明细列表", notes = "获取流水明细列表")
	@RequestMapping(value = "fundLists", method = RequestMethod.POST)
	@ResponseBody
	public Response fundLists(@CurrentUserId Long userId,@RequestBody BalanceHistory balanceHistory){
		balanceHistory.setOrderBy("BALANCE_HISTORY.create_time DESC");
		Page<BalanceHistory> datas=balanceHistoryService.page(balanceHistory);
		return ResponseUtil.ok(datas);
	}
	
	
	//@MagicPermission
	@ApiOperation(value = "获取充值明细列表", notes = "获取充值明细列表")
	@RequestMapping(value = "infundList", method = RequestMethod.POST)
	@ResponseBody
	public Response infundList(HttpServletRequest request, HttpServletResponse response,@CurrentUserId Long userId,@RequestBody GetInfundListRequest getInfundListRequest) {
		logger.debug("获取充值明细列表");
		List<GetInfundListResponse> datas = new ArrayList<GetInfundListResponse>();
		GetInfundListResponse data = null;
		Map<String, Object> params = null;
		List<BalanceHistory> balances = null;
		User user = null;
		
		params = new HashMap<String, Object>();
		
		//查询条件
		if(!(getInfundListRequest.getStart_time() == null || getInfundListRequest.getStart_time().equals(""))){
			params.put("startTime", getInfundListRequest.getStart_time());
		}
		if(!(getInfundListRequest.getEnd_time() == null || getInfundListRequest.getEnd_time().equals(""))){
			params.put("endTime", getInfundListRequest.getEnd_time());
		}
		if(!(getInfundListRequest.getUserId() == null || getInfundListRequest.getUserId().equals(""))){
			params.put("userId", getInfundListRequest.getUserId());
		}
		if(!(getInfundListRequest.getNickName() == null || getInfundListRequest.getNickName().equals(""))){
			params.put("nickName", getInfundListRequest.getNickName());
		}
		
		params.put("type", 1);
		//根据shopId 查找roleId
		if(getInfundListRequest.getShopId()!=null){
			Shop shop = new Shop();
			shop.setId(Long.parseLong(getInfundListRequest.getShopId()));
			shop = shopService.findOne(shop);
			if(shop!=null&&shop.getRoleId()!=null){
				params.put("roleId",shop.getRoleId());
			}else{
				params.put("roleId","-1");
			}
		}
		
		long count = balanceHistoryService.getCount(params);
		
		int pageIndex = getInfundListRequest.getPageIndex_();
		int pageSize = getInfundListRequest.getPageSize_();
		Page<GetInfundListResponse> page = new Page<GetInfundListResponse>(pageIndex,pageSize);
		int limitStart = (pageIndex - 1) * pageSize;
		params.put("limitStart", limitStart);
		
		int limitEnd = pageSize;
		params.put("limitEnd", limitEnd);
		
		params.put("orderBy", "BALANCE_HISTORY.create_time desc");
		balances = balanceHistoryService.getAllList(params);
		
		for(BalanceHistory balance : balances) {
			data = new GetInfundListResponse();
			data.setId(balance.getId());
			data.setTradeNo(balance.getOrderNo());					// 需要修改
			data.setTradeUserId(balance.getUserId());
			User tmpUser = userService.get(balance.getUserId());
			if(tmpUser!=null&&tmpUser.getRoleId()!=null){
				SysRole role = sysRoleService.get(tmpUser.getRoleId());
				if(role!=null){
					data.setShopName(role.getName());	
				}
			}
			
			data.setAmount(balance.getAmount());
		    data.setInfundTime(getStringDateTime(balance.getCreateTime()));
		    params = new HashMap<String, Object>();
			params.put("id", balance.getUserId());
			user = userService.findOne(params);
			
			if(user != null) {
				data.setTradeNickname(user.getNickname());
				datas.add(data);
			} else {
				data.setTradeNickname("");
			}
		  
		}
		page.setData(datas);
		page.setTotalCount((int)count);
		
		return ResponseUtil.ok(page);
	}
	
	//@MagicPermission
	@ApiOperation(value = "系统赠送资金", notes = "系统赠送资金")
	@RequestMapping(value = "giveFund", method = RequestMethod.POST)
	@ResponseBody
	public Response giveFund(HttpServletRequest request, HttpServletResponse response,@RequestBody GiveFundRequest giveFundRequest) {
		logger.debug("系统赠送资金");
		GiveFundResponse data = null;
		Map<String, Object> params = null;
		User user = null;
		BalanceHistory balance = null;
		Timestamp currentTime = new Timestamp((new java.util.Date()).getTime());
		
		if(giveFundRequest.getUserIdOrPhone() == null || giveFundRequest.getUserIdOrPhone().equals("")) {
			return ResponseUtil.error("参数错误");
		}
		
		if(giveFundRequest.getAmount() == null) {
			return ResponseUtil.error("参数错误");
		}
		
		params = new HashMap<String, Object>();
		params.put("key", giveFundRequest.getUserIdOrPhone());
		user = userService.findByIdOrPhone(params);
		if(user == null) {
			return ResponseUtil.error("用户不存在");
		}
		
		balance = new BalanceHistory();
		balance.setUserId(user.getId());
		//系统赠送资金（8）
		balance.setType(giveFundRequest.getType());
		balance.setAmount(giveFundRequest.getAmount());
		// 订单编号
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
		java.util.Date date = new java.util.Date();
		String str = simpleDateFormat.format(date);
		Random random = new Random();
		int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数
		String pointNo = str + rannum;// 当前时间
//		balance.setCurrentAmount(user.getBalance() + giveFundRequest.getAmount());
//		balance.setChangeAmount(giveFundRequest.getAmount());
		balance.setAccountType(0);
		balance.setOrderNo(pointNo);
//		balance.setOrderAccount("");
		balance.setActivityId(0L);
		balance.setCreateTime(currentTime);
//		balance.setObjUserId(0L);
		boolean flag = balanceHistoryService.insert(balance);
		if (giveFundRequest.getIsPresent() != null) {
			user.setCanWithdrawBalance(user.getCanWithdrawBalance()+giveFundRequest.getAmount());
		}else {
			user.setBalance(user.getBalance() + giveFundRequest.getAmount());
		}
		userService.update(user);
		
		if (flag == true) {
			//生成消息
			Message message = new Message();
			message.setUserId(user.getId());
			message.setType(1);
			message.setPushType(1);
			if (giveFundRequest.getIsPresent() != null) {
				message.setContent("恭喜你获得系统赠送可提现金额 +"+giveFundRequest.getAmount().intValue()+"元");
			}else {
				message.setContent("恭喜你获得系统赠送余额 +"+giveFundRequest.getAmount().intValue()+"元");
			}
			
			message.setCreateTime(new Timestamp(new Date().getTime()));
			message.setTitle("系统赠送");
			message.setRemark("系统赠送");
			//推送消息
			messageService.insert(message);
			
			//极光推送
			try {
				MsgPushUtils.addJPush(message.getContent(), user.getId().toString());
			} catch (APIConnectionException e) {
				e.printStackTrace();
			} catch (APIRequestException e) {
				e.printStackTrace();
			}
		}
		
		return ResponseUtil.ok(data);
	}
	
	//@MagicPermission
	@ApiOperation(value = "系统扣除资金", notes = "系统扣除资金")
	@RequestMapping(value = "reduceFund", method = RequestMethod.POST)
	@ResponseBody
	public Response reduceFund(HttpServletRequest request, HttpServletResponse response,@RequestBody ReduceFundRequest reduceFundRequest) {
		logger.debug("系统扣除资金");
		ReduceFundResponse data = null;
		Map<String, Object> params = null;
		User user = null;
		BalanceHistory balance = null;
		Timestamp currentTime = new Timestamp((new java.util.Date()).getTime());
		
		if(reduceFundRequest.getUserIdOrPhone() == null || reduceFundRequest.getUserIdOrPhone().equals("")) {
			return ResponseUtil.error("参数错误");
		}
		
		if(reduceFundRequest.getAmount() == null) {
			return ResponseUtil.error("参数错误");
		}
		
		params = new HashMap<String, Object>();
		params.put("key", reduceFundRequest.getUserIdOrPhone());
		user = userService.findByIdOrPhone(params);
		if(user == null) {
			return ResponseUtil.error("用户不存在");
		}
		if(reduceFundRequest.getAmount() > user.getBalance()) {
			return ResponseUtil.error("帐户余额不足");
		}
		
		balance = new BalanceHistory();
		balance.setUserId(user.getId());
		balance.setAmount(0-reduceFundRequest.getAmount());
//		balance.setType(BalanceHistory.TYPE_SYS_DEDUCT);
		//系统扣钱（类型9）
		balance.setType(reduceFundRequest.getType());
//		balance.setCurrentAmount(user.getBalance() - reduceFundRequest.getAmount());
//		balance.setChangeAmount(0 - reduceFundRequest.getAmount());
		balance.setAmount(reduceFundRequest.getAmount());
		balance.setAccountType(0);
		// 订单编号
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
		java.util.Date date = new java.util.Date();
		String str = simpleDateFormat.format(date);
		Random random = new Random();
		int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数
		String pointNo = str + rannum;// 当前时间
		balance.setOrderNo(pointNo);
//		balance.setOrderAccount("");
		balance.setActivityId(0L);
		balance.setCreateTime(currentTime);
//		balance.setObjUserId(0L);
		boolean flag = balanceHistoryService.insert(balance);
		if (reduceFundRequest.getIsPresent() != null) {
			user.setCanWithdrawBalance(user.getCanWithdrawBalance()-reduceFundRequest.getAmount());
		}else {
			user.setBalance(user.getBalance() - reduceFundRequest.getAmount());
		}
		userService.update(user);
		
		if (flag == true) {
			//生成消息
			Message message = new Message();
			message.setUserId(user.getId());
			message.setType(1);
			message.setPushType(1);
			if (reduceFundRequest.getIsPresent() != null) {
				message.setContent("对不起，您已被系统扣除可提现金额 -"+reduceFundRequest.getAmount().intValue()+"元");
			}else {
				message.setContent("对不起，您已被系统扣除余额 -"+reduceFundRequest.getAmount().intValue()+"元");
			}
			message.setCreateTime(new Timestamp(new Date().getTime()));
			message.setTitle("系统扣除");
			message.setRemark("系统扣除");
			//推送消息
			messageService.insert(message);
			//极光推送
			try {
				MsgPushUtils.addJPush(message.getContent(), user.getId().toString());
			} catch (APIConnectionException e) {
				e.printStackTrace();
			} catch (APIRequestException e) {
				e.printStackTrace();
			}
		}
		
		return ResponseUtil.ok(data);
	}
	
	//@MagicPermission
	@ApiOperation(value = "获取充值面额列表", notes = "获取充值面额列表")
	@RequestMapping(value = "denominationList", method = RequestMethod.POST)
	@ResponseBody
	public Response denominationList(HttpServletRequest request, HttpServletResponse response,@RequestBody GetDenominationListRequest getDenominationListRequest) {
		logger.debug("获取充值面额列表");
		GetDenominationListResponse data = new GetDenominationListResponse();
		Map<String, Object> params = null;
		List<InfundDenomination> denoms = null;
		List<Integer> lst = new ArrayList<Integer>();
		
		params = new HashMap<String, Object>();
		denoms = infundDenominationService.find(params);
		
		for(InfundDenomination d : denoms) {
			lst.add(d.getAmount());
		}
		
		data.setAmount(lst);
		
		return ResponseUtil.ok(data);
	}
	
	//@MagicPermission
	@ApiOperation(value = "充值面额设置", notes = "充值面额设置")
	@RequestMapping(value = "denominationSetup", method = RequestMethod.POST)
	@ResponseBody
	public Response denominationSetup(HttpServletRequest request, HttpServletResponse response,@RequestBody DenominationSetupRequest denominationSetupRequest) {
		logger.debug("充值面额设置");
		DenominationSetupResponse data = null;
		Map<String, Object> params = null;
		List<Integer> lstDenos = denominationSetupRequest.getAmounts();
		InfundDenomination d = null;
		
		params = new HashMap<String, Object>();
		infundDenominationService.remove(params);
		
		for(Integer value : lstDenos) {
			d = new InfundDenomination();
			d.setAmount(value);
			infundDenominationService.insert(d);
		}
		
		return ResponseUtil.ok(data);
	}
	
	//@MagicPermission
	@ApiOperation(value = "获取积分明细列表", notes = "获取积分明细列表")
	@RequestMapping(value = "pointsList", method = RequestMethod.POST)
	@ResponseBody
	public Response pointsList(HttpServletRequest request, HttpServletResponse response,@CurrentUserId Long userId,@RequestBody GetPointsListRequest getPointsListRequest) {
		logger.debug("获取积分明细列表");
		List<GetPointsListResponse> datas = new ArrayList<GetPointsListResponse>();
		GetPointsListResponse data = null;
		Map<String, Object> params = getPageMap(request);
		List<PointsHistory> pointss = null;
		User user = null;
		
		//条件查询
		if(!(getPointsListRequest.getStart_time() == null || getPointsListRequest.getStart_time().equals(""))){
			params.put("startTime", getPointsListRequest.getStart_time());
		}
		if(!(getPointsListRequest.getEnd_time() == null || getPointsListRequest.getEnd_time().equals(""))){
			params.put("endTime", getPointsListRequest.getEnd_time());
		}
		if(!(getPointsListRequest.getUserId() == null || getPointsListRequest.getUserId().equals(""))){
			params.put("userId", getPointsListRequest.getUserId());
		}
		
		if(!(getPointsListRequest.getOrderNo() == null || getPointsListRequest.getOrderNo().equals(""))){
			params.put("orderNo", getPointsListRequest.getOrderNo());
		}
		if(!(getPointsListRequest.getObjId() == null || getPointsListRequest.getObjId().equals(""))){
			params.put("objId", getPointsListRequest.getObjId());
		}
		if(!(getPointsListRequest.getObjNickName() == null || getPointsListRequest.getObjNickName().equals(""))){
			params.put("objNickName", getPointsListRequest.getObjNickName());
		}
		if(!(getPointsListRequest.getNickName() == null || getPointsListRequest.getNickName().equals(""))){
			params.put("nickName", getPointsListRequest.getNickName());
		}
		
		
		params.put("orderBy", "POINTS_HISTORY.create_time desc");
		
		//根据shopId 查找roleId
		if(getPointsListRequest.getShopId()!=null){
			Shop shop = new Shop();
			shop.setId(Long.parseLong(getPointsListRequest.getShopId()));
			shop = shopService.findOne(shop);
			if(shop!=null&&shop.getRoleId()!=null){
			   params.put("roleId",shop.getRoleId());
			}else{
				 params.put("roleId","-1");
			}
		}
		
		//分页
		long count = pointsHistoryService.getCount(params);
		int pageIndex = getPointsListRequest.getPageIndex_();
		int pageSize = getPointsListRequest.getPageSize_();
		Page<GetPointsListResponse> page = new Page<GetPointsListResponse>(pageIndex,pageSize);
		int limitStart = (pageIndex - 1) * pageSize;
		params.put("limitStart", limitStart);
		
		int limitEnd = pageSize;
		params.put("limitEnd", limitEnd);
		
		pointss = pointsHistoryService.getAllList(params);
		
		for (PointsHistory points : pointss) {
			data = new GetPointsListResponse();
			data.setId(points.getId());
			data.setTradeNo(points.getPointNo());					// 需要修改
			data.setTradeUserId(points.getUserId());
			data.setTradeType(points.getType());
			data.setTradeTypeStr(getPointsTypeStr(points.getType()));
			data.setTradePrice((points.getChangePoints() > 0 ? "+" : "") + points.getChangePoints() + "积分");
			data.setTradeObjUserId(points.getObjUserId());
			data.setTradeTime(getStringDateTime(points.getCreateTime()));
			
			user = userService.get(points.getUserId());
			if (user != null) {
				data.setTradeObjNickname(user.getNickname());
			} else {
				data.setTradeObjNickname("admin");
			}
			
			if(user!=null&&user.getRoleId()!=null){
				SysRole role = sysRoleService.get(user.getRoleId());
				if(role!=null){
					data.setShopName(role.getName());
				}
			}
			
			params = new HashMap<String, Object>();
			if(!(getPointsListRequest.getNickName() == null || getPointsListRequest.getNickName().equals(""))){
				params.put("nickname", getPointsListRequest.getNickName());
			}
			params.put("id", points.getUserId());
			//用户权限
			//获得权限和roleID
			User user2 = userDao.getRoleId(userId);
			if (user2.getAuthority()==1) {
			}
			
			if (user2.getAuthority()==2) {
				params.put("roleId",user2.getRoleId());
			}
			user = userService.findOne(params);
			if(user != null) {
				data.setTradeNickname(user.getNickname());
				datas.add(data);
			} else {
				data.setTradeNickname("");
			}
		 
		}
		
		page.setData(datas);
		page.setTotalCount((int)count);
		
		return ResponseUtil.ok(page);
	}
	
	//@MagicPermission
	@ApiOperation(value = "系统赠送积分", notes = "系统赠送积分")
	@RequestMapping(value = "givePoints", method = RequestMethod.POST)
	@ResponseBody
	public Response givePoints(HttpServletRequest request, HttpServletResponse response,@RequestBody GivePointsRequest givePointsRequest) {
		logger.debug("系统赠送积分");
		GivePointsResponse data = null;
		Map<String, Object> params = null;
		User user = null;
		PointsHistory points = null;
		Timestamp currentTime = new Timestamp((new java.util.Date()).getTime());
		
		if(givePointsRequest.getUserIdOrPhone() == null || givePointsRequest.getUserIdOrPhone().equals("")) {
			return ResponseUtil.error("参数错误");
		}
		
		if(givePointsRequest.getAmount() == null) {
			return ResponseUtil.error("参数错误");
		}
		
		params = new HashMap<String, Object>();
		params.put("key", givePointsRequest.getUserIdOrPhone());
		user = userService.findByIdOrPhone(params);
		if(user == null) {
			return ResponseUtil.error("用户不存在");
		}
		// 订单编号
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
		java.util.Date date = new java.util.Date();
		String str = simpleDateFormat.format(date);
		Random random = new Random();
		int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数
		String pointNo = str + rannum;// 当前时间

		
		points = new PointsHistory();
		points.setUserId(user.getId());
		points.setType(PointsHistory.POINT_TYPE_SYS_GIVE);
		points.setCurrentPoints(user.getPoints() + givePointsRequest.getAmount().intValue());
		points.setChangePoints(givePointsRequest.getAmount().intValue());
		points.setCreateTime(currentTime);
		points.setObjUserId(0L);
		points.setPointNo(pointNo);
		
		pointsHistoryService.insert(points);
		
		BalanceHistory balance = null;
		balance = new BalanceHistory();
		balance.setUserId(user.getId());
		//系统赠送积分（13）
		balance.setType(13);
		balance.setCredits(givePointsRequest.getAmount().intValue());
//		balance.setCurrentAmount(user.getBalance() + giveFundRequest.getAmount());
//		balance.setChangeAmount(giveFundRequest.getAmount());
		balance.setAccountType(0);
		balance.setOrderNo(pointNo);
//		balance.setOrderAccount("");
		balance.setActivityId(0L);
		balance.setCreateTime(currentTime);
//		balance.setObjUserId(0L);
		boolean flag = balanceHistoryService.insert(balance);
		user.setPoints(user.getPoints() + givePointsRequest.getAmount().intValue());
		userService.update(user);
		
		if (flag == true) {
			//生成消息
			Message message = new Message();
			message.setUserId(user.getId());
			message.setType(1);
			message.setPushType(1);
			message.setContent("恭喜你获得系统赠送积分 +"+givePointsRequest.getAmount().intValue()+"积分");
			message.setCreateTime(new Timestamp(new Date().getTime()));
			message.setTitle("系统赠送");
			message.setRemark("系统赠送");
			//推送消息
			messageService.insert(message);
			//极光推送
			try {
				MsgPushUtils.addJPush(message.getContent(), user.getId().toString());
			} catch (APIConnectionException e) {
				e.printStackTrace();
			} catch (APIRequestException e) {
				e.printStackTrace();
			}
		}
		
		return ResponseUtil.ok(data);
	}
	
	//@MagicPermission
	@ApiOperation(value = "系统扣除积分", notes = "系统扣除积分")
	@RequestMapping(value = "reducePoints", method = RequestMethod.POST)
	@ResponseBody
	public Response reducePoints(HttpServletRequest request, HttpServletResponse response,@RequestBody ReducePointsRequest reducePointsRequest) {
		logger.debug("系统扣除积分");
		ReducePointsResponse data = null;
		Map<String, Object> params = null;
		User user = null;
		PointsHistory points = null;
		Timestamp currentTime = new Timestamp((new java.util.Date()).getTime());
		
		if(reducePointsRequest.getUserIdOrPhone() == null || reducePointsRequest.getUserIdOrPhone().equals("")) {
			return ResponseUtil.error("参数错误");
		}
		
		if(reducePointsRequest.getAmount() == null) {
			return ResponseUtil.error("参数错误");
		}
		
		params = new HashMap<String, Object>();
		params.put("key", reducePointsRequest.getUserIdOrPhone());
		user = userService.findByIdOrPhone(params);
		if(user == null) {
			return ResponseUtil.error("用户不存在");
		}
		if(reducePointsRequest.getAmount() > user.getPoints()) {
			return ResponseUtil.error("帐户积分不足");
		}
		
		// 订单编号
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
		java.util.Date date = new java.util.Date();
		String str = simpleDateFormat.format(date);
		Random random = new Random();
		int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数
		String pointNo = str + rannum;// 当前时间
		
		points = new PointsHistory();
		points.setUserId(user.getId());
		points.setType(PointsHistory.POINT_TYPE_SYS_DEDUCT);
		points.setCurrentPoints(user.getPoints() - reducePointsRequest.getAmount().intValue());
		points.setChangePoints(0 - reducePointsRequest.getAmount().intValue());
		points.setCreateTime(currentTime);
		points.setObjUserId(0L);
		points.setPointNo(pointNo);
		
		pointsHistoryService.insert(points);
		
		BalanceHistory balance = null;
		balance = new BalanceHistory();
		balance.setUserId(user.getId());
		//系统扣除积分（14）
		balance.setType(14);
		balance.setCredits(0 - reducePointsRequest.getAmount().intValue());
//		balance.setCurrentAmount(user.getBalance() + giveFundRequest.getAmount());
//		balance.setChangeAmount(giveFundRequest.getAmount());
		balance.setAccountType(0);
		balance.setOrderNo(pointNo);
//		balance.setOrderAccount("");
		balance.setActivityId(0L);
		balance.setCreateTime(currentTime);
//		balance.setObjUserId(0L);
		boolean flag = balanceHistoryService.insert(balance);
		
		user.setPoints(user.getPoints() - reducePointsRequest.getAmount().intValue());
		userService.update(user);
		
		if (flag == true) {
			//生成消息
			Message message = new Message();
			message.setUserId(user.getId());
			message.setType(1);
			message.setPushType(1);
			message.setContent("对不起，您已被系统扣除积分 -"+reducePointsRequest.getAmount().intValue()+"积分");
			message.setCreateTime(new Timestamp(new Date().getTime()));
			message.setTitle("系统扣除");
			message.setRemark("系统扣除");
			//推送消息
			messageService.insert(message);
			//极光推送
			try {
				MsgPushUtils.addJPush(message.getContent(), user.getId().toString());
			} catch (APIConnectionException e) {
				e.printStackTrace();
			} catch (APIRequestException e) {
				e.printStackTrace();
			}
		}
		
		
		return ResponseUtil.ok(data);
	}
	
	@ApiOperation(value = "获取积分设置列表", notes = "获取积分设置列表")
	@RequestMapping(value = "integralList", method = RequestMethod.POST)
	@ResponseBody
	public Response integralList(@CurrentUserId Long userId,@RequestBody IntegralSetting integralSetting){
		integralSetting.setOrderBy("INTEGRAL_SETTING.create_time DESC");
		List<IntegralSetting> datas=integralSettingService.find(integralSetting);
		return ResponseUtil.ok(datas);
	}
	
	@ApiOperation(value = "设置积分列表", notes = "设置积分列表")
	@RequestMapping(value = "integralhandle", method = RequestMethod.POST)
	@ResponseBody
	public Response integralhandle(@CurrentUserId Long userId,@RequestBody IntegralSetting integralSetting){
		Map<String, Object> params = null;
		params = new HashMap<String, Object>();
		//修改积分设置表
		integralSettingService.remove(params);
		integralSettingService.insert(integralSetting);
		
		//修改系统配置表
		SysConfig sysConfig = new SysConfig();
		if (integralSetting.getSignPoint()!=null) {
			//修改签到积分
			sysConfig.setValue(String.valueOf(integralSetting.getSignPoint()));
			sysConfig.setId(11l);
			sysConfigService.update(sysConfig);
		}
		if (integralSetting.getRegister()!=null) {
			//修改登录积分
			sysConfig = new SysConfig();
			sysConfig.setValue(String.valueOf(integralSetting.getRegister()));
			sysConfig.setId(1l);
			sysConfigService.update(sysConfig);
		}
		
		return ResponseUtil.ok();
	}
	
	private String getPointsTypeStr(int type) {
		switch(type) {
		case PointsHistory.POINT_TYPE_SIGN :	
			return "每日签到";
		case PointsHistory.POINT_TYPE_BUY :	
			return "购买积分商品";
		case PointsHistory.POINT_TYPE_INVITE :
			return "邀请好友注册且登录成功";
		case PointsHistory.POINT_TYPE_REGISTER :
			return "注册赠送";
		case PointsHistory.POINT_TYPE_SYS_GIVE :
			return "系统赠送";
		case PointsHistory.POINT_TYPE_SYS_DEDUCT :
			return "系统扣除";
		default :
			break;
		}
		return "未知";
	}
	
	/*private String getBalanceTypeStr(int type) {
		switch(type) {
		case BalanceHistory.TYPE_INFUND :	
			return "充值";
		case BalanceHistory.TYPE_BUY_GOODS :	
			return "购买商品";
		case BalanceHistory.TYPE_REFUND :
			return "商品退款";
		case BalanceHistory.TYPE_ACTIVITY_ENROLL :
			return "报名活动";
		case BalanceHistory.TYPE_SYS_GIVE :
			return "系统赠送";
		case BalanceHistory.TYPE_SYS_DEDUCT :
			return "系统扣除";
		case BalanceHistory.TYPE_SUBORDINATE_CONSUME :
			return "下级消费奖励";
		default :
			break;
		}
		return "未知";
	}*/
	
	@SuppressWarnings("unused")
	private SysConfig getSysConfig(String field) {
		SysConfig sysConfig = null;
		Map<String, Object> params = new HashMap<String, Object>();
		params = new HashMap<String, Object>();
	 	params.put("field", field);
	 	sysConfig = sysConfigService.findOne(params);
		return sysConfig;
	}
	
	
	@ApiOperation(value = "查询提现管理列表", notes = "查询提现管理列表")
	@RequestMapping(value = "check", method = RequestMethod.POST)
	@ResponseBody
	private Response check(@RequestBody WithdrawHistory withdrawHistory) {
	withdrawHistory.setOrderBy("WITHDRAW_HISTORY.create_time desc");
	
	//根据shop查询roleId
	if(withdrawHistory.getShopId()!=null){
		Shop shop = new Shop();
		shop.setId(Long.parseLong(withdrawHistory.getShopId()));
		shop = shopService.findOne(shop);
		if(shop!=null&&shop.getRoleId()!=null){
			withdrawHistory.setRoleId(shop.getRoleId()+"");
		}else{
			withdrawHistory.setRoleId("-1");
		}
	}
	
	Page<WithdrawHistory> data=withdrawHistoryService.PageList(withdrawHistory);
	
	List<WithdrawHistory> list=new ArrayList<WithdrawHistory>();
	for (int i = 0; i < data.getData().size(); i++) {
		WithdrawHistory with=data.getData().get(i);
		with.setAmountIn(0);
		with.setAmountSuccess(0);
		if (with.getStatus()==1) {
			WithdrawHistory w=new WithdrawHistory();
			w.setStatus(1);
			List<WithdrawHistory> wList=withdrawHistoryDao.findUserIds(w);
			
			WithdrawHistory w2=new WithdrawHistory();
			w2.setStatus(2);
			List<WithdrawHistory> wList2=withdrawHistoryDao.findUserIds(w2);
		    for (int j = 0; j < wList.size(); j++) {
				if (wList.get(j).getUserId().equals(with.getUserId())) {
					with.setAmountIn(wList.get(j).getAmount());
				}
			}
		    for (int j = 0; j < wList2.size(); j++) {
				if (wList2.get(j).getUserId().equals(with.getUserId())) {
					with.setAmountSuccess(wList2.get(j).getAmount());
				}
			}
			
		}
		if (with.getStatus()==2) {
			WithdrawHistory w=new WithdrawHistory();
			w.setStatus(2);
			List<WithdrawHistory> wList=withdrawHistoryDao.findUserIds(w);
			
			WithdrawHistory w2=new WithdrawHistory();
			w2.setStatus(1);
			List<WithdrawHistory> wList2=withdrawHistoryDao.findUserIds(w2);
		    for (int j = 0; j < wList.size(); j++) {
				if (wList.get(j).getUserId().equals(with.getUserId())) {
					with.setAmountSuccess(wList.get(j).getAmount());
				}
			}
		    for (int j = 0; j < wList2.size(); j++) {
				if (wList2.get(j).getUserId().equals(with.getUserId())) {
					with.setAmountIn(wList2.get(j).getAmount());
				}
			}
		}
		
      
		User user = userService.get(with.getUserId());
		if(user!=null&&user.getRoleId()!=null){
			SysRole role = sysRoleService.get(user.getRoleId());
			if(role!=null){
				with.setShopName(role.getName());
			}
		}
		
	
		list.add(with);
	}
	
	
	data.setData(list);
	return ResponseUtil.ok(data);
	}
	
	
	
	@ApiOperation(value = "提现设置&提现说明设置", notes = "提现设置&提现说明设置")
	@RequestMapping(value = "withdraw", method = RequestMethod.POST)
	@ResponseBody
	private Response withdraw(@RequestBody WithdrawConfig withdrawConfig) {
     withdrawConfig.setId(1L);
	 int flag=withdrawConfigService.update(withdrawConfig);
	return ResponseUtil.ok(flag);
	}

	
	@ApiOperation(value = "提现说明查询", notes = "提现说明查询")
	@RequestMapping(value = "withContent", method = RequestMethod.POST)
	@ResponseBody
	private Response withContent(@RequestBody WithdrawConfig withdrawConfig) {
		
	 List<WithdrawConfig> data=withdrawConfigService.find(withdrawConfig);
	 if (data.size()>0) {
		 return ResponseUtil.ok(data.get(0));
	}
	return ResponseUtil.ok(withdrawConfig);
	}
	
	
	@ApiOperation(value = "提现导入", notes = "提现导入")
	@RequestMapping(value = "withImport", method = RequestMethod.POST)
	@ResponseBody
	private Response withImport(@RequestBody WithdrawHistory withdrawHistory)  {
		try {
			
		
	
		for (int i = 0; i < withdrawHistory.getWithList().size(); i++) {
			
			WithdrawHistory with=withdrawHistory.getWithList().get(i);
			WithdrawHistory with2=new WithdrawHistory();
			with2.setId(with.getId());
			with2.setStatus(with.getStatus());
			withdrawHistoryService.update(with2);
			
			if (withdrawHistory.getWithList().get(i).getStatus()==2 || withdrawHistory.getWithList().get(i).getStatus().equals("2")) {
				User u=userDao.getUserByUserId(withdrawHistory.getWithList().get(i).getUserId());

    			User u2=new User();
    			
    			u2.setId(u.getId());
    			Float f=u.getCanWithdrawBalance()-(float)(withdrawHistory.getWithList().get(i).getAmount());
    			u2.setCanWithdrawBalance(f);
	    		userService.update(u2);
				
				//生成消息
				Message message = new Message();
				message.setUserId(withdrawHistory.getWithList().get(i).getUserId());
				message.setType(1);
				message.setPushType(1);
				
				message.setContent("恭喜你，你申请提现"+withdrawHistory.getWithList().get(i).getAmount()+"元成功，请注意查收您的银行卡到账消息（若有疑问可联系客服人员）！");
				
				message.setCreateTime(new Timestamp(new Date().getTime()));
				message.setTitle("用户提现");
				message.setRemark("用户提现");
				//推送消息
				messageService.insert(message);
				
				//极光推送
				try {
					MsgPushUtils.addJPush(message.getContent(), withdrawHistory.getWithList().get(i).getUserId().toString());
				} catch (Exception e) {
//					logger.error("提现推送失败！");
				} 
			}
			
			if (withdrawHistory.getWithList().get(i).getStatus()==3 || withdrawHistory.getWithList().get(i).getStatus().equals("3")) {
	    		User u=userDao.getUserByUserId(withdrawHistory.getWithList().get(i).getUserId());
	    		
	    			User u2=new User();
	    			
	    			u2.setId(u.getId());
	    			u2.setCanWithdrawBalance(u.getCanWithdrawBalance()+withdrawHistory.getWithList().get(i).getAmount());
		    		userService.update(u2);
	    		
	    		
				//生成消息
				Message message = new Message();
				message.setUserId(withdrawHistory.getWithList().get(i).getUserId());
				message.setType(1);
				message.setPushType(1);
				
				message.setContent("对不起，你申请提现"+withdrawHistory.getWithList().get(i).getAmount()+"元失败，提现金额已自动返还至账户）！");
				
				message.setCreateTime(new Timestamp(new Date().getTime()));
				message.setTitle("用户提现");
				message.setRemark("用户提现");
				//推送消息
				messageService.insert(message);
				
				//极光推送
				try {
					MsgPushUtils.addJPush(message.getContent(), withdrawHistory.getWithList().get(i).getUserId().toString());
				} catch (Exception e) {
//					logger.error("提现推送失败！");
				} 
			}
			
			
		}
		
	   return ResponseUtil.ok(1);
		} catch (Exception e) {
			 return ResponseUtil.ok(1);
		}
	}
	
	
	@IgnoreAuth
	@ApiOperation(value = "提现记录添加", notes = "提现记录添加")
	@RequestMapping(value = "withInsert", method = RequestMethod.POST)
	@ResponseBody
	private Response withInsert(@CurrentUserId Long userId,@RequestBody WithdrawHistory withdrawHistory) {
		
		userId=22L;
		WithdrawConfig con=new WithdrawConfig();
		List<WithdrawConfig> conList=withdrawConfigService.find(con);

		withdrawHistory.setUserId(userId);
		Long count=withdrawHistoryDao.getMaxCount(withdrawHistory);
		
		if (conList.size()>0) {
			WithdrawConfig config=conList.get(0);
			
			if (count.intValue()>=config.getMaxCount()) {
				return ResponseUtil.ok(3);
			}
			
			//今日提现金额拦截
			if(withdrawHistory.getAmount()>config.getMinAmount()){
				return ResponseUtil.ok(2);
			}
		}
		
		BankAccount bank=new BankAccount();
		bank.setId(withdrawHistory.getId());
		List<BankAccount> bankList=bankAccountService.find(bank);
		if (bankList.size()>0) {
			BankAccount account=bankList.get(0);
			withdrawHistory.setBankType(account.getBankId().intValue());
			withdrawHistory.setAccountType(1);
			withdrawHistory.setAccount(account.getCardNo());
		}
		
		User user=new User();
		user.setId(userId);
		List<User> userList=userService.find(user);
		if (userList.size()>0) {
			User u=userList.get(0);
			withdrawHistory.setName(u.getNickname());
			withdrawHistory.setPhone(u.getPhone());
		}
		withdrawHistory.setWithNum(getRandom());
		withdrawHistory.setUserId(userId);
		withdrawHistory.setStatus(1);
		Timestamp now = new Timestamp(System.currentTimeMillis()); 
		withdrawHistory.setCreateTime(now);
		withdrawHistory.setHandleTime(now);
	boolean flag=withdrawHistoryService.insert(withdrawHistory);
	int f=0;
	float res=0;
	if (flag==true) {
	    f=1;
	    if ( userList.size()>0) {
	    	User user3=userList.get(0);
	    	if (user3.getCanWithdrawBalance() >= withdrawHistory.getAmount()) {
	    		res=user3.getCanWithdrawBalance()-withdrawHistory.getAmount();
	    		
	    		User user2=new User();
	    		user2.setId(userId);
	    		user2.setCanWithdrawBalance(res);
	    		user2.setSuccessWithdrawBalance(user3.getSuccessWithdrawBalance()+withdrawHistory.getAmount());
	    		userService.update(user2);
			}
	    	
		}
	    
		//生成消息
		Message message = new Message();
		message.setUserId(userId);
		message.setType(1);
		message.setPushType(1);
		
		message.setContent("恭喜你，你申请提现"+withdrawHistory.getAmount()+"元成功，请注意查收您的银行卡到账消息（若有疑问可联系客服人员）！");
		
		message.setCreateTime(new Timestamp(new Date().getTime()));
		message.setTitle("用户提现");
		message.setRemark("用户提现");
		//推送消息
		messageService.insert(message);
		
		//极光推送
		try {
			MsgPushUtils.addJPush(message.getContent(), userId.toString());
		} catch (APIConnectionException e) {
			e.printStackTrace();
		} catch (APIRequestException e) {
			e.printStackTrace();
		}
	   
	}
	
	
	return ResponseUtil.ok(f);
	}
	
	public static String getRandom(){
		String randomStr="";
		for (int i = 0; i < 9; i++) {
		int random=(int)(Math.random()*9);
		if(randomStr.indexOf(random+"")!=-1){
		i=i-1;
		}else{
		randomStr+=random;
		}
		}
		return randomStr;
	}

}
